package 算法_回溯;

import java.util.ArrayList;
import java.util.Collections;

public class Perm {
    public static void main(String[] args) {
        ArrayList<String> s = new ArrayList<>();
        s.add("a");
        s.add("b");
        s.add("c");
        ArrayList<ArrayList<String>> t = new ArrayList<>();
        get_perm(0, s, t);
        System.out.println(t.toString());
    }

    private static void get_perm(int idx, ArrayList<String> s, ArrayList<ArrayList<String>> t) {
        if (idx == s.size())
            t.add(new ArrayList<>(s));
        else {
            for (int i = idx; i < s.size(); i++) {
                Collections.swap(s, i, idx);
                get_perm(idx + 1, s, t);
                Collections.swap(s, i, idx);
            }
        }
    }
}
